import axios from "axios";
// eslint-disable-next-line
export default {
  //获取优惠券数据
  get: ({ curPage, eachPage }) =>
    axios
      .get("/api/coupons", {
        params: {
          curPage,
          eachPage,
        },
      })
      .then(({ data }) => data),
  //新增优惠券
  addCoupon: ({ name, discount, minMoney, deadLine, navsId }) =>
    axios
      .post("/api/coupons", {
        name,
        discount,
        minMoney,
        deadLine,
        navsId,
      })
      .then(({ data }) => data),
  //删除优惠券
  delCoupon: (_id) =>
    axios
      .delete("/api/coupons/del", { data: { _id } })
      .then(({ data }) => data),
  //通过id获取某一条优惠券数据
  getOne: (_id) =>
    axios
      .get(`/api/coupons/${_id}`, { params: { _id } })
      .then((response) => response.data),
  //通过id修改某一条优惠券数据
  changeOne: ({ _id, name, discount, minMoney, deadLine, navsId }) =>
    axios
      .put(`/api/coupons/change`, {
        _id,
        name,
        discount,
        minMoney,
        deadLine,
        navsId,
      })
      .then((response) => response.data),
  //查询优惠券
  searchCoupon: (data) => {
    console.log(data);
    axios
      .get(`/api/coupons/searchCou`, { params: data })
      .then((response) => console.log(response));
  },
};
